'use strict';
const path = require('path');
const isDevelopment = process.env.NODE_ENV === 'development';
const isProduction = process.env.NODE_ENV === 'production';

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

module.exports = {
  publicPath: '/',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: true,
  filenameHashing: true,
  productionSourceMap: isDevelopment,
  runtimeCompiler: true,
  devServer: {
    host: '0.0.0.0',
    https: false,
    port: 2323,
    open: true,
    proxy: {
      '/': {
        target: 'http://192.168.40.200:30331',
        ws: true,
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/': '/',
        },
      },
    },
    disableHostCheck: false,
  },
  configureWebpack: (config) => {
    const configure = {
      plugins: [
        // 打包分析插件。需要安装的插件：webpack-bundle-analyzer
        isProduction &&
          new BundleAnalyzerPlugin({
            analyzerMode: 'server',
            analyzerHost: '127.0.0.1',
            analyzerPort: 8787,
            reportFilename: 'report.html',
            defaultSizes: 'parsed',
            openAnalyzer: false,
            generateStatsFile: false,
            statsFilename: 'stats.json',
            statsOptions: null,
            logLevel: 'info',
          }),
      ].filter(Boolean),
    };
    return configure;
  },
  pluginOptions: {
    // 全局样式引入插件配置。需要安装的插件：style-resources-loader、vue-cli-plugin-style-resources-loader
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [path.resolve(__dirname, './src/styles/index.less')],
    },
  },
};
